package com.csdj.t309.geamtest.config;

import com.csdj.t309.geamtest.service.RedisService;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * web相关的配置
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Resource
    private RedisService redisService;

    /**
     * 配置拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor(redisService))
                //需要拦截的路径
                .addPathPatterns("/**")
                //不需要拦截的路径
                .excludePathPatterns("/user/login","/mail/send","/user/selpassword","/user/adduser","/user/emailTesting","/image/**","/weixin/**","/ws/test","/wesockets");
    }
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/wesockets");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/image/**").addResourceLocations("file:D:/123456/");
        WebMvcConfigurer.super.addResourceHandlers(registry);
    }

}
